<!--
描述：艺术中心-系统管理-学生信息-新增组件
开发人：hqj
开发日期：2017年12月15日
-->

<template lang="pug">
    kalix-dialog.user-add(bizKey="student" ref="kalixBizDialog" v-bind:form-model.sync="formModel" v-bind:targetURL="targetURL")
        div.el-form.kalix-form-table(slot="dialogFormSlot")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="入学年份" prop="entranceYear" v-bind:rules="rules.entranceYear" v-bind:label-width="labelWidth")
                    kalix-date-picker(v-model="formModel.entranceYear" type="year" v-on:change="change")
                el-form-item.s-flex_item.kalix-form-table-td(label="专业" prop="majorId" v-bind:rules="rules.majorId" v-bind:label-width="labelWidth")
                    kalix-object-select2(v-model="formModel.majorId" v-bind:objectsUrl="majorURL" v-bind:label="'cnName'" v-on:objectSelected="majorSelected")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="班级" prop="classId" v-bind:rules="rules.classId" v-bind:label-width="labelWidth")
                    kalix-object-select2(v-model="formModel.classId" v-bind:objectsUrl="classURL" v-bind:label="'name'")
                el-form-item.s-flex_item.kalix-form-table-td(label="辅导员" prop="instructor" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.instructor")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="学生培养层次" prop="trainingLevel" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.trainingLevel")
                el-form-item.s-flex_item.kalix-form-table-td(label="学习年限" prop="period" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.period")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="学号" prop="code" v-bind:rules="rules.code" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.code")
                el-form-item.s-flex_item.kalix-form-table-td(label="姓名" prop="name" v-bind:rules="rules.name" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.name")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="身份证号" prop="identificationCard" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.identificationCard")
                el-form-item.s-flex_item.kalix-form-table-td(label="性别" prop="sex" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.sex" appName="admin" dictType="性别")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="出生日期" prop="birthday" v-bind:label-width="labelWidth")
                    kalix-date-picker(v-model="formModel.birthday")
                el-form-item.s-flex_item.kalix-form-table-td(label="民族" prop="nation" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.nation")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="籍贯" prop="placeOfOrigin" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.placeOfOrigin")
                el-form-item.s-flex_item.kalix-form-table-td(label="家庭联系电话" prop="homePhone" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.homePhone")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="政治面貌" prop="politicalStatus" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.politicalStatus")
                el-form-item.s-flex_item.kalix-form-table-td(label="入党(团)时间" prop="joinPartyDate" v-bind:label-width="labelWidth")
                    kalix-date-picker(v-model="formModel.joinPartyDate")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="现联系地址" prop="address" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.address")
                el-form-item.s-flex_item.kalix-form-table-td(label="邮政编码" prop="postalcode" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.postalcode")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="固定电话" prop="phone" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.phone")
                el-form-item.s-flex_item.kalix-form-table-td(label="手机" prop="mobile" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.mobile")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="邮箱" prop="email" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.email")
                el-form-item.s-flex_item.kalix-form-table-td(label="生源省份" prop="province" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.province" appName="admin" dictType="省份")
</template>

<script type="text/ecmascript-6">
    import FormModel from './model'
    import {StudentURL} from '../../config.toml'

    export default {
        name: 'AdminStudentAdd',
        data() {
            return {
                formModel: Object.assign({}, FormModel),
                rules: {
                    entranceYear: [{required: true, message: '请选择入学年份', trigger: 'change'}],
                    majorId: [{required: true, type: 'number', message: '请选择专业', trigger: 'change'}],
                    classId: [{required: true, type: 'number', message: '请选择班级', trigger: 'change'}],
                    code: [{required: true, message: '请输入学号', trigger: 'blur'}],
                    name: [{required: true, message: '请输入姓名', trigger: 'blur'}]
                },
                targetURL: StudentURL,
                majorURL: '',
                classURL: '',
                labelWidth: '140px'
            }
        },
        components: {},
        created() {
        },
        methods: {
            change(value) {
                this.formModel.majorId = null
                this.formModel.classId = null
                if (value) {
                    let date = new Date(value)
                    let grade = date.getFullYear()
                    this.majorURL = '/camel/rest/grades/grade/' + grade + '/majorinfos'
                } else {
                    this.majorURL = ''
                }
            },
            majorSelected(major) {
                this.formModel.classId = null
                if (major && !this.$M_IsEmptyObject(major)) {
                    let date = new Date(this.formModel.entranceYear)
                    let grade = date.getFullYear()
                    this.classURL = '/camel/rest/getClassInfos?grade=' + grade + '&majorId=' + major.id
                } else {
                    this.classURL = ''
                }
            }
        }
    }
</script>

<style scoped lang="stylus">
</style>
